package com.youlemall.shop.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**运营商运营管理后台登录
 * 2 * @Author: kevin
 * 3 * @Date: 2019/7/18 15:30
 * 4
 */

@Controller
public class LoginController {


	@PostMapping("/login")
	public String login(String username,String password){
		try {
			Subject subject = SecurityUtils.getSubject();
			UsernamePasswordToken token = new UsernamePasswordToken(username, password);
			subject.login(token);
			if (subject.isAuthenticated()){
				return "redirect:/admin/index.html";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "redirect:/shoplogin.html";
	}

	@GetMapping("/findLoginName")
	@ResponseBody
	public String findLoginName(){
		return 	SecurityUtils.getSubject().getPrincipal().toString();
	}
}
